<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test4</title>
    <link rel="icon" th:href="@{/favicon.png}" type="image/png"/>
    <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<!--人力资源API测试测试-->
<div id="app">
    <button @click="getAllEmployees">获取所有人力资源</button>
    <button @click="getTemp">生成人力</button>
    <input type="number" v-model="id" placeholder="ID">
    <input type="text" v-model="name" placeholder="姓名">
    <button @click="sure">确认</button>
    <button @click="levelUp">升级</button>
</div>
<script type="module">
    const { createApp } = Vue
    createApp({
        data() {
            return {
                username: 'Wooming',
                password: 'MyServer123456',
                id: 0,
                name: ''
            }
        },
        created(){
            axios.post('../../api/public/login',{
                username: this.username,
                password: this.password
            }).then((response) => {
                console.log(response.data.code)
                // 存储于 localStorage
                localStorage.setItem('jwt', response.data.data)
            })
        },
        methods: {
            getAllEmployees() {
                axios.get('../../api/hr/get', {
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('jwt')
                    }
                }).then((r) => {
                    console.log(r.data)
                })
            },
            getTemp() {
                axios.get('../../api/hr/random', {
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('jwt')
                    }
                }).then((r) => {
                    console.log(r.data)
                })
            },
            sure() {
                axios.post('../../api/hr/sure',{
                    id: this.id,
                    name: this.name
                },{
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('jwt')
                    }
                }).then((r) => {
                    console.log(r.data)
                })
            },
            levelUp() {
                axios.post('../../api/hr/levelUp', {}, {
                    params: {
                        id: this.id
                    },
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('jwt')
                    }
                }).then((r) => {
                    console.log(r.data)
                })
            }
        }
    }).mount('#app')
</script>
</body>
</html>